/*create by 2017/07/10 表格公共组件*/
import React from "react";
import Relay from 'react-relay';
import ReactKey from "../../../../util/ReactKey";
import { Table, message } from 'antd';
import Util from "../../../../util/Util"
import '../css/style.css';
import ListProductionCensusMutation from '../mutation/ListProductionCensus'

export default class headerList extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            workShopId: null,
            tableHead:[],
            tableList:[]
        }
    }

    getTableData(workShopId,productionType){
        this.setState({
            workShopId: workShopId,
            productionType: productionType
        })
        Relay.Store.commitUpdate(
            new ListProductionCensusMutation({
                workShop: workShopId,
                productionType: productionType,
            }),
            {
                onFailure: () => {
                    message.error('网络请求失败');
                    this.setState({
                        loading: false
                    })
                },
                onSuccess: (res) => {
                    let data = res.listProductionCensus.listProductionCensus;
                    if(data.errorCode == 0){
                        this.setState({
                            loading: false,
                            tableHead: JSON.parse(data.listTime),
                            tableList: data.productionCensusModel
                        })

                    } else {
                        message.error(data.value);
                        this.setState({
                            loading: false
                        })
                    }
                }
            }
        );
    }
    updateData() {
        this.getTableData(this.state.workShopId,this.state.productionType)
    }

    render() {
        const { tableHead,tableList } = this.state;
        const head = tableHead[0];
        const columns = head ? [{
            title: '班组',
            dataIndex: 'groupName',
            key: 'groupName',
        }, {
            title: Util.dayRate(Util.timeStamp(head[1])),
            dataIndex: 'day1',
            key: 'day1',
        }, {
            title: Util.dayRate(Util.timeStamp(head[2])),
            dataIndex: 'day2',
            key: 'day2',
        },{
            title: Util.dayRate(Util.timeStamp(head[3])),
            dataIndex: 'day3',
            key: 'day3',
        },{
            title: Util.dayRate(Util.timeStamp(head[4])),
            dataIndex: 'day4',
            key: 'day4',
        },{
            title: Util.dayRate(Util.timeStamp(head[5])),
            dataIndex: 'day5',
            key: 'day5',
        },{
            title: Util.dayRate(Util.timeStamp(head[6])),
            dataIndex: 'day6',
            key: 'day6',
        },{
            title: Util.dayRate(Util.timeStamp(head[7])),
            dataIndex: 'day7',
            key: 'day7',
        }] : null

        return(
            <div>
                {
                    head && head[1] ? <Table columns={columns}
                                       rowKey={ReactKey.key}
                                       dataSource={tableList}
                                       loading={this.props.loading}
                                       className='order_table statistics_com_table'
                    /> : (
                        <div className="proofing_progress_none">
                            <img src={require("../../img/empty.png")} alt=""/>
                            <span>暂无数据</span>
                        </div>
                    )
                }
            </div>
        )
    }
}